package org.yzh.scheduler.model.entity;

import io.swagger.annotations.ApiModelProperty;
import org.yzh.scheduler.model.enums.ContentType;
import org.yzh.scheduler.model.enums.HttpMethod;

import java.time.LocalDateTime;

public class JobLogDO {

    @ApiModelProperty("ID")
    private Integer id;

    @ApiModelProperty("任务ID")
    private Integer jobId;

    @ApiModelProperty("任务名称(接口名)")
    private String jobName;

    @ApiModelProperty("任务组(系统名)")
    private String jobGroup;

    @ApiModelProperty("HttpMethod")
    private HttpMethod method;

    @ApiModelProperty("HttpURL")
    private String url;

    @ApiModelProperty("HttpContentType")
    private ContentType contentType;

    @ApiModelProperty("HttpParameters")
    private String parameters;

    @ApiModelProperty("触发时间")
    private LocalDateTime triggerTime;

    @ApiModelProperty("触发响应码")
    private Integer triggerCode;

    @ApiModelProperty("触发响应报文")
    private String triggerMsg;

    @ApiModelProperty("回调时间")
    private LocalDateTime callbackTime;

    @ApiModelProperty("回调响应码")
    private Integer callbackCode;

    @ApiModelProperty("回调报文")
    private String callbackMsg;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getJobId() {
        return jobId;
    }

    public void setJobId(Integer jobId) {
        this.jobId = jobId;
    }

    public String getJobName() {
        return jobName;
    }

    public void setJobName(String jobName) {
        this.jobName = jobName;
    }

    public String getJobGroup() {
        return jobGroup;
    }

    public void setJobGroup(String jobGroup) {
        this.jobGroup = jobGroup;
    }

    public HttpMethod getMethod() {
        return method;
    }

    public void setMethod(HttpMethod method) {
        this.method = method;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public ContentType getContentType() {
        return contentType;
    }

    public void setContentType(ContentType contentType) {
        this.contentType = contentType;
    }

    public String getParameters() {
        return parameters;
    }

    public void setParameters(String parameters) {
        this.parameters = parameters;
    }

    public LocalDateTime getTriggerTime() {
        return triggerTime;
    }

    public void setTriggerTime(LocalDateTime triggerTime) {
        this.triggerTime = triggerTime;
    }

    public Integer getTriggerCode() {
        return triggerCode;
    }

    public void setTriggerCode(Integer triggerCode) {
        this.triggerCode = triggerCode;
    }

    public String getTriggerMsg() {
        return triggerMsg;
    }

    public void setTriggerMsg(String triggerMsg) {
        this.triggerMsg = format(triggerMsg);
    }

    public LocalDateTime getCallbackTime() {
        return callbackTime;
    }

    public void setCallbackTime(LocalDateTime callbackTime) {
        this.callbackTime = callbackTime;
    }

    public Integer getCallbackCode() {
        return callbackCode;
    }

    public void setCallbackCode(Integer callbackCode) {
        this.callbackCode = callbackCode;
    }

    public String getCallbackMsg() {
        return callbackMsg;
    }

    public void setCallbackMsg(String callbackMsg) {
        this.callbackMsg = format(callbackMsg);
    }

    public static String format(String message) {
        if (message != null) {
            message = message.replace("  ", " ").replace("  ", " ").replace("\t\t", "\t");
            if (message.length() > 2048)
                message = message.substring(0, 2047);
        }
        return message;
    }

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        JobLogDO other = (JobLogDO) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        return result;
    }
}